/*=+--+=#=+--     Unmanned Aerial System Management Software      --+=#=+--+=#*\
|          Copyright (C) 2011 Regents of the University of Colorado.           |
|                             All Rights Reserved.                             |

     This program is free software: you can redistribute it and/or modify
     it under the terms of the GNU General Public License version 2 as
     published by the Free Software Foundation.

     This program is distributed in the hope that it will be useful,
     but WITHOUT ANY WARRANTY; without even the implied warranty of
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     GNU General Public License for more details.

     You should have received a copy of the GNU General Public License
     along with this program.  If not, see <http://www.gnu.org/licenses/>.

            Jack Elston                       Cory Dixon                        
|           elstonj@colorado.edu              dixonc@colorado.edu              |
|                                                                              |
\*=+--+=#=+--                 --+=#=+--+=#=+--                    --+=#=+--+=#*/

/*!
  \file sensorStruct.h
  \brief header file for sensor communications

  \author Jack Elston
  $Date: 2005/09/07 20:51:43 $
  */

#ifndef __SENSORSTRUCT_H
#define __SENSORSTRUCT_H

#include <inttypes.h>

/*<-------Defines--------->*/
/*! \brief	number of servos on the system. */
#define NUM_SERVOS 6
/*! \brief	number of neighbor nodes to track. */
#define SOEKRIS_MAX_LINKSTAT 8

  /**********************\
  |     system wide      |
  \**********************/
typedef struct
{
	uint8_t reset;
	uint8_t experiment_number;
	uint8_t experiment_state;
} __attribute__ ((packed)) SystemMsg;

  /**********************\
  |        servo         |
  \**********************/
/*! \brief commanded servo positions. */
typedef struct {
	uint16_t roll; //!< roll command [1 to 65536]
	uint16_t pitch; //!< pitch command [1 to 65536]
	uint16_t yaw; //!< pitch command [1 to 65536]
	uint16_t throttle; //!< throttle command [1 to 65536]
} __attribute__ ((packed))Servos;

/*! \brief a public global variable. */
typedef struct {
	uint16_t pan;
	uint16_t tilt;
	uint16_t buttons;        // 16 on/off buttons
	uint16_t kill;
} __attribute__ ((packed))ServoButtons;

  /**********************\
  | command and control  |
  \**********************/

enum GNCFlightModes { MODE_RC=0, MODE_SA, MODE_FC };

typedef struct
{
	int8_t   flightMode;     // mode of control
} __attribute__ ((packed))GNCStruct;


typedef struct {
	uint16_t roll;
	uint16_t pitch;
	uint16_t yaw;
} __attribute__ ((packed))ControlGain;

enum ExperimentWaypoints { NONE=0, RESET_WAYPT, COMM_LIMIT_WAYPT, TEMP_LIMIT_WAYPT}; 
// NONE used for system init

typedef struct{
	uint8_t Type; //from the enumerated type
	uint8_t Waypoint;
	float Value;
} __attribute__ ((packed)) ExperimentWaypt;

typedef struct
{
	//float loopGain;
	float kp;
	float kd;
	float kpi; 
	float kdi; 
} __attribute__ ((packed)) TurnRateGains;

typedef struct
{
	uint8_t mode; // 0 is off, 1 is test, 2 is actually run
	uint8_t nodeID; // 255 means any, 0 means none (or simulation)
	int16_t R; // desired R to track (R => RSSI or R => gps orbit (-implise CW))
} __attribute__ ((packed)) TurnRateMode;

typedef struct
{
	int16_t deltaX;	   // scaled to cm/s
	int16_t deltaY;	   // scaled to cm/s
	uint8_t gpsMoving;	// actually move the gps point
} __attribute__ ((packed)) GPSStandoffMoving;

typedef struct
{
	uint8_t trackNode;	// if == 0, unset, elseif >0 node id, else == 255 for artificial
	uint8_t trackMoving;	// if set = 1, adjust for known speeds (when known)
	float   gain;        // gain on angle
} __attribute__ ((packed)) GPStandoffTracker;

typedef struct
{
	//float loopGain;
	float kp;
	float kd;
} __attribute__ ((packed)) TurnRateGains0;

typedef struct
{
	float kpi;
	float kdi;
} __attribute__ ((packed)) TurnRateGains1;

typedef struct
{
	uint8_t mode;	 // off=0, testing=1, running=2
	uint8_t nodeID; // IP address of tracked node
	int16_t R;      // if rssi orbit => RSSI, if gps standoff => radius
	float turnRate; // rad/s
} __attribute__ ((packed)) TurnRateVal;

  /**********************\
  |  external autopilot  |
  \**********************/

typedef struct{
	uint8_t value;
} __attribute__ ((packed))PiccoloReqWaypt;

typedef struct{
	uint8_t value;
} __attribute__ ((packed))PiccoloTrackWaypt;

typedef struct{
	int8_t RSSI;
	int8_t AvailableForCommand;
	uint16_t TwelveV;
	uint16_t FiveV;
} __attribute__ ((packed))PiccoloSysDiag;

typedef struct{
	uint8_t This;
	float Lat;
	uint16_t Alt;
	uint8_t Flags;
} __attribute__ ((packed))PiccoloWaypt0;

typedef struct{
	uint8_t This;
	float Lon;
	uint8_t OrbitRad;
	uint8_t WindFind;
	uint8_t Next;
} __attribute__ ((packed))PiccoloWaypt1;

typedef struct{
	int16_t TAS;
	int16_t VNorth;
	int16_t VEast;
} __attribute__ ((packed))PiccoloSpeed;

  /**********************\
  |         imu          |
  \**********************/

typedef struct {
	int16_t roll;
	int16_t pitch;
	int16_t yaw;
} __attribute__ ((packed))IMUAngles;

typedef struct {
	int16_t roll;
	int16_t pitch;
	int16_t yaw;
} __attribute__ ((packed))IMURates;

typedef struct {
	int16_t Ax;
	int16_t Ay;
	int16_t Az;
} __attribute__ ((packed))IMUAccelerations;

typedef struct {
	float rates;
	float accel;
} __attribute__ ((packed))IMUCutoff;

  /**********************\
  |    communications    |
  \**********************/

typedef struct {
	uint8_t signal;
} __attribute__ ((packed))GroundComm;

typedef struct{
	int8_t Signal; //dBm
	int8_t Noise; //dBm
	int8_t gsConnected; //dBm
} __attribute__ ((packed)) PayloadComms;

typedef struct{
	uint8_t id;		// node number
	uint8_t type;		// node type, ARES, Yellow, MNR 
} __attribute__ ((packed)) IDStruct;

typedef struct
{
	uint8_t nodeID;	// 4th octect of IP address
	uint16_t lastRx;	// milli-sec from last packet
	float RSSI;
} __attribute__ ((packed)) WirelessRSSI;

  /**********************\
  |      air data        |
  \**********************/

typedef struct{
	int16_t trueAirSpeed;
	int32_t barometricAlt;
} __attribute__ ((packed)) AirData;

  /**********************\
  |        gps           |
  \**********************/

typedef struct{
	float track;		// track made good in degrees true
	float trackMag;		// track made good in degrees magnetic
	float SOG;		// speed over ground in knots
} __attribute__ ((packed))GP_VTG;

typedef struct{
	float lat;
	float lon;
} __attribute__ ((packed))GPSLatLon;

typedef struct{
	uint8_t hours;
	uint8_t minutes;
	uint8_t seconds;
} __attribute__ ((packed))GPSUTC;

typedef struct{
	uint8_t quality;
	uint8_t sats;
	float hdop;
} __attribute__ ((packed))GPSAccuracy;

typedef struct{
	float alt;
	float geoSep;
} __attribute__ ((packed))GPSAlt;

typedef struct{
	float trackTru;
	float trackMag;
} __attribute__ ((packed))GPSTrack;

typedef struct{
	float SOG;
} __attribute__ ((packed))GPSSOG;

  /**********************\
  |  health and status   |
  \**********************/

  /**********************\
  |       payload        |
  \**********************/

typedef struct{
	float temp;
	float humidity;
} __attribute__ ((packed))PayloadData0;

typedef struct{
	float pressure;
	float mag;
} __attribute__ ((packed))PayloadData1;

/*<------End Defines------>*/

/*<---Global Variables---->*/
/*<-End Global Variables-->*/

#endif //__SENSORSTRUCT_H
